package cn.app.edu.projectpracticeofpracticaltraining.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.app.edu.projectpracticeofpracticaltraining.R;
import cn.app.edu.projectpracticeofpracticaltraining.entity.BannerEntity;

public class BannerHomeFragmentAdapter extends PagerAdapter {

    private Context mContext;
    private List<BannerEntity.DataBean> mList;

    public BannerHomeFragmentAdapter(Context mContext, List<BannerEntity.DataBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == o;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
//        return super.instantiateItem(container, position);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.banner_item_home_fragment, null);
        ImageView mImages = inflate.findViewById(R.id.iv_banner_banner_item_home_fragment);
        String ImageUrl = mList.get(position).getImagePath();
        Glide.with(mContext).load(ImageUrl).into(mImages);
        container.addView(inflate);
        return inflate;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
//        super.destroyItem(container, position, object);
        container.removeView((View) object);
    }

}
